package com.school.repository;

import com.school.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface StudentRepository extends JpaRepository<Student, Long> {
    Optional<Student> findByStudentId(String studentId);
    
    @Query("SELECT s FROM Student s WHERE s.classId = :classId")
    List<Student> findByClassId(@Param("classId") Long classId);
    
    @Query("SELECT s FROM Student s WHERE s.name LIKE %:keyword% OR s.studentId LIKE %:keyword%")
    List<Student> findByNameOrStudentIdContaining(@Param("keyword") String keyword);
    
    @Query("SELECT s FROM Student s WHERE s.classId = :classId AND (s.name LIKE %:keyword% OR s.studentId LIKE %:keyword%)")
    List<Student> findByClassIdAndNameOrStudentIdContaining(@Param("classId") Long classId, @Param("keyword") String keyword);
}
